import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vitejs.dev/config/

// vite配置项   跟webpack一样  vite也是高配置前端构建工具

export default ({ mode }) => defineConfig({
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    vue(),
  ],
  resolve:{
    alias:{
      '@': path.resolve(__dirname,'src'),
      '~': path.resolve(__dirname,'./'),

    },
    extensions: ['.vue', '.js', 'jsx', '.json'],

  },
  base:'./',
  // base: mode == 'development' ? './' : (mode == 'beta' ? '//s.baidu.com/beta/xxx' : '//s.baidu.com/release/xxx') // 静态资源路径配置
  server: {
    proxy:{
      // 凡是遇到/api的请求 都映射到target属性 转发到属性地址
        '/api': {
          target: 'http://backend-api-02.newbee.ltd/manage-api/v1', // 凡是遇到 /api 路径的请求，都映射到 target 属性
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '') // 重写 api 为 空，就是去掉它
        }
      
    }
  }
})
